<?php

// +----------------------------------------------------------------------
// | 支付模型
// +----------------------------------------------------------------------
// | Copyright (c) 2015-2022 http://www.yicmf.com, All rights reserved.
// +----------------------------------------------------------------------
// | Author: 微尘 <yicmf@qq.com>
// +----------------------------------------------------------------------

namespace app\model\pay;

use app\store\model\Order;
use app\store\model\Store;
use app\ucenter\model\User;
use yicmf\tools\FlowSn;

class Pay extends Common
{

    public function user()
    {
        return $this->belongsTo(User::class);
    }

    /**
     * 写入修改
     * @param $data
     */
    public static function onBeforeInsert($data)
    {
        $data['api_pay_status'] = 0;
        $data['dead_time'] = time_format('1 day');
        if (!isset($data['pay_sn'])) {
            if ('order' == $data['type']) {
                $data['pay_sn'] = FlowSn::build(6);
            } elseif ('recharge' == $data['type']) {
                $data['pay_sn'] = FlowSn::build(7);
            } else {
                $data['pay_sn'] = FlowSn::build(9);
            }
        }

    }
}
